package com.ruoyi.qywx.getway.api;

import cn.hutool.json.JSONUtil;
import com.ruoyi.common.core.cache.Meta;
import com.ruoyi.qywx.getway.request.TxRequest;
import com.ruoyi.qywx.getway.request.TxResponse;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author : hcl
 * @Date : 2023/8/22 14:50
 */
@Slf4j
public class MessageEventApi {
    /**
     * 发送新客户欢迎语
     * https://developer.work.weixin.qq.com/document/path/92599
     */
    public static void sendExternalContactWelcome(Meta meta, Map<String, Object> welcome) {
        log.info("发送欢迎语...........");
        TxResponse post = TxRequest.getInstance(meta.getCorpid(), meta.getAppSecret())
                .post("/cgi-bin/externalcontact/send_welcome_msg", JSONUtil.toJsonStr(welcome));
        if (!post.isSuccess()) {
            log.error("发送欢迎语失败:{}", post.getError());
        }
    }
}
